package source.events.action;

import source.model.DataHandler;
import source.model.type.ActionResult;
import source.model.type.GameObjectType;
import source.model.utility.EatAtJoesIterator;
import source.model.ObjectID;
import source.view.MainScreen;
public class NextBase implements Action{

	private int playerID;
	
	public NextBase(int playerID)
	{
		this.playerID = playerID;
	}
	public ActionResult execute(DataHandler dh)
	{
		EatAtJoesIterator bases = dh.getBaseIterator();

		if(bases == null)
		{
			MainScreen.writeToConsole("Player owns no bases to select");
			return ActionResult.FAILED;
		}
		if(dh.getCurrentSelection().objectType() == GameObjectType.BASE && bases.getLength() == 1)
		{
			MainScreen.writeToConsole("Player owns no other base to select");
			return ActionResult.FAILED;
		}
		ObjectID nextBase = bases.getNext();
		if (nextBase == null)
		{
			//MainScreen.writeToConsole("NextBase:  EatAtJoesIterator.getNext is null");
			return ActionResult.IMPOSSIBLE;
		}
		dh.setCurrentSelection(nextBase);
		MainScreen.writeToConsole("Next Base was successfully selected");
		return ActionResult.SUCCESS;
	}
}
